package com.it.dao;

import com.it.base.BaseDAO;
import com.it.bean.UserBasicBean;

import java.util.List;

public class UserBasicDaoImpl extends BaseDAO<UserBasicBean> implements UserBasicDao {
    @Override
    public void addUserBasic(UserBasicBean userBasicBean) throws Exception {
        String sql = "insert into t_user_basic value (?,?,?,?,?)";
        super.executeUpdate(sql, 0, userBasicBean.getLoginId(), userBasicBean.getNickName(), userBasicBean.getPwd(), userBasicBean.getHeadImg());

    }

    @Override
    public UserBasicBean getUserBasicByLoginId(String loginId,String pwd) throws Exception {
        String sql = "select * from t_user_basic where loginId = ? and pwd = ?";
        return super.load(sql, loginId,pwd);
    }

    @Override
    public List<UserBasicBean> getFriendListByUser(UserBasicBean userBasicBean) throws Exception {
        String sql = "\tSELECT DISTINCT\n" +
                "                t3.id AS id,\n" +
                "                t3.loginId AS loginId,\n" +
                "                t3.nickName AS nickName,\n" +
                "                t3.pwd AS pwd,\n" +
                "                t3.headImg AS headImg \n" +
                "                FROM\n" +
                "                t_user_basic t1\n" +
                "                 JOIN t_friend t2 ON t1.id = t2.uid\n" +
                "                 JOIN t_user_basic t3 ON t2.fid = t3.id\n" +
                "\t\t\t\t\t\t\t\t\n" +
                "\t\t\t\t\t\t\t\t\n" +
                "                WHERE\n" +
                "                t1.id = ? \n" +
                "                AND t1.id != t2.fid";

        return    super.executeQuery(sql,userBasicBean.getId());
    }

    @Override
    public UserBasicBean getUserBasicBeanById(String id) throws Exception {
        String sql = "select * from t_user_basic where id = ?";
        return super.load(sql, id);
    }
}
